package com.aisile.wemedia.controller.v1;

import com.aisile.apis.wemedia.WmNewsControllerApi;
import com.aisile.model.admin.dtos.NewsAuthDto;
import com.aisile.model.common.dtos.ResponseResult;
import com.aisile.model.media.dtos.WmNewsDto;
import com.aisile.model.media.dtos.WmNewsPageReqDto;
import com.aisile.model.media.pojos.WmNews;
import com.aisile.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther:yry
 * @Date:2024/1/6 0006
 * @VERSON:1.0
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController implements WmNewsControllerApi {

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    @Override
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findAll(dto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult saveNews(@RequestBody WmNewsDto dto) {
       if(dto.getStatus() == 1){
           // 提交
           return wmNewsService.saveNews(dto,(short)1);
       }else{
           // 草稿
           return wmNewsService.saveNews(dto,(short)0);
       }
    }

    //  ？id    /{id}
    @GetMapping("/findbyid/{id}")
    @Override
    public ResponseResult findById(@PathVariable("id") Integer id) {
        return wmNewsService.findWmNewsById(id);
    }

    @DeleteMapping("/delbyid/{id}")
    @Override
    public ResponseResult delById(@PathVariable("id") Integer id) {
        return wmNewsService.delById(id);
    }

    @PutMapping("/downorup")
    @Override
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto.getId(),dto.getEnable());
    }

    @GetMapping("/findone/{id}")
    @Override
    public WmNews findByIdToFeign(@PathVariable("id") Integer id) {
        return wmNewsService.getById(id);
    }

    @PostMapping("/update")
    @Override
    public WmNews updateWmNewsForFeign(@RequestBody WmNews wmNews) {
        wmNewsService.updateById(wmNews);
        return wmNews;
    }

    @GetMapping("/find_release")
    @Override
    public List<Integer> findRelease() {
        return wmNewsService.findRelease();
    }

    @PostMapping("/find_list")
    @Override
    public ResponseResult findList(@RequestBody NewsAuthDto dto) {
        return wmNewsService.findList(dto);
    }

    @GetMapping("/find_wmnewsvo/{id}")
    @Override
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
        return wmNewsService.findWmNewsVo(id);
    }


}
